let Sequelize = require('sequelize')
let {sqlConfig} = require('./config')

console.log("sequelize-config========", sqlConfig.password)

let sequelize = new Sequelize(sqlConfig.database, sqlConfig.user, sqlConfig.password, {
  logging: function (sql) {
    // logger为log4js的Logger实例
    if (process.env.NODE_ENV !== 'production') {
      console.log(sql)
    }
  },
  port: sqlConfig.port,
  host: sqlConfig.host,
  dialect: 'mysql',
  dialectOptions: {
    dateStrings: true,
    typeCast: true
  },
  pool: {
    max: 20,
    min: 1,
    acquire: 60000,
    idle: 10000
  },
  timezone: '+08:00' //东八时区
});

// 测试数据库是否连接成功
sequelize.authenticate().then(res => {
  console.log('MySql Connection Success!', res)
}).catch(err => {
  console.error('MySql Connection Error', err)
})

exports.sequelize = sequelize;
